package com.itheima.mapper;

import com.itheima.annotation.AutoFill;
import com.itheima.entity.Menu;
import com.itheima.entity.MenuChildren;
import com.itheima.entity.Role;
import com.itheima.enumeration.OperationDateType;
import com.itheima.vo.MenuChildrenVO;
import com.itheima.vo.RoleVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @projectName: kafka
 * @package: com.itheima.mapper
 * @className: SysMenuMapper
 * @author: Eric
 * @description: TODO
 * @date: 2023/9/21 14:40
 * @version: 1.0
 */
@Mapper
public interface SysMenuMapper {
    /**
     * 按pid选择
     *
     * @param pid pid
     * @return {@link List}<{@link MenuChildren}>
     */
    List<MenuChildren> selectByPid(int pid);

    /**
     * 添加菜单
     *
     * @param menu 菜单
     */
    @AutoFill(OperationDateType.INSERT)
    @Insert("insert into sys_menu (component,icon,is_cache,is_link,is_show,mark,path,pid,redirect,sort,title,type,create_date,update_date) values (#{component}, #{icon},#{isCache},#{isLink},#{isShow},#{mark},#{path},#{pid},#{redirect} ,#{sort} , #{title}, #{type},#{createDate},#{updateDate})")
    void addMenu(Menu menu);

    /**
     * 删除菜单
     *
     * @param id id
     */
    @Delete("delete from sys_menu where id = #{id}")
    void deleteMenu(Integer id);

    /**
     * 按id选择故障数据
     *
     * @param id id
     * @return {@link String}
     */
    @Select("select default_data from sys_menu where id=#{id}")
    String selectdeFaultDataById(Integer id);

    /**
     * 按id选择
     *
     * @param id id
     * @return {@link List}<{@link Integer}>
     */
    List<Integer> selectById(Integer id);

    /**
     * 更新菜单
     *
     * @param menu 菜单
     */
    void updateMenu(Menu menu);

    /**
     * 按id选择菜单
     *
     * @param id id
     * @return {@link Menu}
     */
    @Select("select id, pid, path, component, title, icon, is_show, is_cache, is_link, redirect, create_date, update_date, del_flag, type, sort, mark, default_data from sys_menu where id = #{id}")
    Menu selectMenuById(Integer id);

    /**
     * 按角色id选择菜单id
     *
     * @param id id
     * @return {@link Integer}
     */
    @Select("select menu_id from sys_role_menu where role_id=#{id}")
    Integer selectMenuIdByRoleId(String id);
}
